<template>
  <el-container class="home-container">
    <el-header><!-- 头部区 -->
      <div>
        <span id="fontLogo">智能快递柜后台管理系统</span>
      </div>
      <el-menu
          :default-active="activeIndex"
          class="el-menu-demo"
          mode="horizontal"
          @select="handleSelect"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          id="indexMenu">
        <el-menu-item index="1" @click="shouye">首页</el-menu-item>
        <el-menu-item index="2" @click="expressList">会员</el-menu-item>
        <el-menu-item index="3" @click="goToMachine">柜机</el-menu-item>
        <el-menu-item index="4" @click="baoguo">包裹</el-menu-item>
        <el-menu-item index="5" @click="tiaozhuan">财务</el-menu-item>
        <el-menu-item index="6" @click="other">其他</el-menu-item>
      </el-menu>
      <div>
        <span id="fontName">{{this.name}}</span>
      </div>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="210px" hight="100%">
        <el-menu
            :default-active="activeIndex"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b">

          <el-menu-item index="1">
            <i class="el-icon-menu"></i>
            <span @click="expressList">快递员列表</span>
          </el-menu-item>
          <el-menu-item index="2">
            <i class="el-icon-menu"></i>
            <span slot="title" >快递员认证审核</span>
          </el-menu-item>
          <el-menu-item index="3">
            <i class="el-icon-setting"></i>
            <span slot="title" @click="expressMember">普通会员列表</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <el-table v-loading="loading" :data="this.expressAuthListList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="ID" align="center" prop="registerIp" >
            <template slot-scope="scope">
              <span @click="detialById(scope.row.registerIp,scope.row.iid)" style="color: #1890ff;">{{scope.row.registerIp}}</span>
            </template>
          </el-table-column>
          <el-table-column label="手机号" align="center" prop="phone" >
            <template slot-scope="scope">
              {{scope.row.areaCode+' '+scope.row.phone}}
            </template>
          </el-table-column>
          <el-table-column label="认证类型" align="center" prop="authType" >
          <template slot-scope="scope">
            <span v-if="scope.row.authType==1">快递员认证</span>
            <span v-if="scope.row.authType==2">实名认证</span>
          </template>
          </el-table-column>
          <el-table-column label="证件类型" align="center" prop="documentType" >
            <template slot-scope="scope">
              <span v-if="scope.row.documentType==1">工牌/名片</span>
              <span v-if="scope.row.documentType==2">身份证</span>
            </template>
          </el-table-column>
          <el-table-column label="认证图片" align="center" prop="authImage" >
            <template slot-scope="scope">
              <el-image
                  style="width: 100px; height: 100px"
                  :src="scope.row.workCardImage"
                  :fit="fit"></el-image>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" prop="createDate" width="180">
            <template slot-scope="scope">
              {{scope.row.createDate|format('yyyy-MM-dd hh:mm:ss')}}
            </template>
          </el-table-column>
          <el-table-column label="审核时间" align="center" prop="passDate" width="180">
            <template slot-scope="scope">
              {{scope.row.passDate|format('yyyy-MM-dd hh:mm:ss')}}
            </template>
          </el-table-column>
          <el-table-column label="状态" align="center" prop="statusa" >
            <template slot-scope="scope">
              <span v-if="scope.row.statusa==1">已通过</span>
              <span v-if="scope.row.statusa==2">待审核</span>
              <span v-if="scope.row.statusa==3">已拒绝</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
                <el-button
                    size="mini"
                    type="text"
                    @click="updateAuthFalse(scope.row)"
                    v-if="scope.row.statusa==2"
                >拒绝</el-button>
                <el-button
                    size="mini"
                    type="text"
                    @click="updateAuthTrue(scope.row.registerIp,scope.row.iid,scope.row.authType)"
                    v-if="scope.row.statusa==2"
                >同意</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div>
<!--          //分页-->
          <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="pageNumber"
              :page-sizes="[2, 4, 6, 8]"
              :page-size=pageSize
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
          </el-pagination>
        </div>
        <!-- 添加或修改快递员列表对话框 -->
        <el-dialog title="提示" :visible.sync="open" width="500px" append-to-body>
          <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            您确定要 拒绝 该快递员认证审核？请在下方填写 拒绝 原因：
            <el-form-item label="中文原因" prop="refuseCn">
              <el-input type="textarea" v-model="form.refuseCn"></el-input>
            </el-form-item>

            <el-form-item label="英文原因" prop="refuseEn">
              <el-input type="textarea" v-model="form.refuseEn"></el-input>
            </el-form-item>

          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
// import {listExpressList} from "@/api/expressList/expressList";
import axios from "axios";
export default {
  data() {
    return {
      //分页
      pageNumber: 1,
      pageSize: 4,
      total: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      // 快递员列表表格数据
      expressAuthListList: [{

      }],
      open: false,
      // 查询参数
      // 表单参数
      //分页
      form: {
        id:'',
      },
      // 表单校验
      rules: {
        isDel: [
          { required: true, message: "逻辑删除 1否 2是  不能为空", trigger: "blur" }
        ],
      },
      activeIndex: '2',
      name: sessionStorage.getItem("name"),
    };
  },
  created() {
    this.getList();
    if (this.name==null){
      this.name="未登录";
      // this.$router.push("/login");
    }
    //分页

  },
  methods: {
    //分页
    getList() {
      axios.get('http://localhost:10020/expressList/authList?pageNum='+this.pageNumber+'&pageSize='+this.pageSize).then(response=>{
        this.expressAuthListList=response.data.list;
        this.total=response.data.total;
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize=val;
      this.getList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNumber=val;
      this.getList();
    },
    // 跳转详情页面
    detialById(id,iid){
      this.$router.push(
          {path: "/expressAuthDetial",
            query: {
              id: id,
              iid:iid,
            },
          })
    },
    // 页面跳转
    xitong(){
      this.$router.push(
          {path: "/OutSystems"}
      )
    },
    baoguo(){
      this.$router.push(
          {path: "/OutPackage"}
      )
    },
    notice() {
      this.$router.push(
          {path: "/HomePage"}
      )
    },
    //跳转其他页面
    other() {
      this.$router.push(
          {path: "/otherView"}
      )
    },
    shouye(){
      this.$router.push(
          {path: "/"}
      )
    },
    // 页面跳转
    expressList(){
      this.$router.push(
          {path: "/expressList"}
      )
    },
    // 页面跳转
    expressMember(){
      this.$router.push(
          {path: "/expressMember"}
      )
    },

    // 状态变更
    updateAuthFalse(data){

      this.open = true;
      this.form=data;
    },
    goToMachine(){
      this.$router.push(
          {path: "/machineHome"}
      )
    },
    //添加确定按钮
    submitForm(){
      axios.post("http://localhost:10020/expressList/updateRefuseReason",this.form).then(response =>{
        this.form = response.data;
        this.$message("拒绝成功");
        this.open = false;
        this.getList();
      })
      // axios.put("http://localhost:10020/expressList/updateAuthFalse?id="+id).then(response =>{
      //   this.form = response.data;
      //   this.getList();
      // })
    },
    tiaozhuan(){
      this.$router.push({
        path:'/zhanghuPage'
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        refuseCn: null,
        refuseEn: null,
      };
      this.resetForm("form");
    },
    // 状态变更
    updateAuthTrue(id,iid,authType){
      console.log(iid+','+id)
      this.$confirm('确定要通过审核？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
              axios.put('http://localhost:10020/expressList/updateAuthTure?id='+id+'&iid='+iid+'&authType='+authType).then(response =>{
          this.form = response.data;
          this.getList();
        });
        this.$message({
          type: 'success',
          message: '审核通过！'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    handleSelect(key) {
      console.log(key);
    },


    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

  },
  filters:{
    format(value,arg){
      function dateFormat(date, format) {
        if (typeof date === "string") {
          var mts = date.match(/(\/Date\((\d+)\)\/)/);
          if (mts && mts.length >= 3) {
            date = parseInt(mts[2]);
          }
        }
        date = new Date(date);
        if (!date || date.toUTCString() == "Invalid Date") {
          return "";
        }
        var map = {
          "M": date.getMonth() + 1, //月份
          "d": date.getDate(), //日
          "h": date.getHours(), //小时
          "m": date.getMinutes(), //分
          "s": date.getSeconds(), //秒
          "q": Math.floor((date.getMonth() + 3) / 3), //季度
          "S": date.getMilliseconds() //毫秒
        };
        format = format.replace(/([yMdhmsqS])+/g, function (all, t) {
          var v = map[t];
          if (v !== undefined) {
            if (all.length > 1) {
              v = '0' + v;
              v = v.substr(v.length - 2);
            }
            return v;
          } else if (t === 'y') {
            return (date.getFullYear() + '').substr(4 - all.length);
          }
          return all;
        });
        return format;
      }

      return dateFormat(value,arg);

    }
  },
};
</script>

<style lang="less">
#app {
  margin-top: 0;
}

.home-container {
  height: 100%;
}

.el-header {
  background-color: #545c64;
  display: flex; //设置显示为flex布局
  justify-content: space-between; //设置为flex左右布局
  padding-left: 0; //左内边距为0（Logo贴左边）
  align-items: center; //元素上下居中（防止右边按钮贴上下边）
  color: #fff;
  font-size: 18px;

  > div {
    //内嵌的div样式
    display: flex;
    align-items: center; //Logo和文字上下居中
    #fontLogo {
      width: 200px;
      margin-left: 10px; //文字左侧设置间距，防止与Logo紧贴
    }
    #fontName {
      width: 120px;
      margin-right: 10px;
    }
  }
}

#indexMenu {
  width: 100%;
}

.el-menu {
  background-color: #545c64;
}

.el-aside {
  background-color: #545c64;
  scrollbar-width: none; /* firefox */
  -ms-overflow-style: none; /* IE 10+ */
  overflow-x: hidden;
  overflow-y: auto;
}

.el-main {
  background-color: #eaedf1;
  height: 1000px;
}
</style>
